﻿@{
    List<DataAccess.Models.AgencyUsers> users = new List<DataAccess.Models.AgencyUsers>();
    users = (List<DataAccess.Models.AgencyUsers>)ViewBag.Users;
}
@model  DataAccess.Models.Robot


<script src="~/Scripts/plugins/jquery.min.js"></script>
<script src="~/Scripts/plugins/layer/layer.min.js"></script>
@section Scripts{ 
    <script src="~/Scripts/plugins/validate/jquery.validate.min.js"></script>
    <script src="~/Scripts/plugins/validate/messages_zh.min.js"></script>
    <script src="~/Scripts/plugins/bootstrap.min.js"></script>
    <script src="~/Scripts/plugins/content.min.js"></script>
    <script src="~/Scripts/sys/lib/common_raw.js"></script>

    <script src="~/Scripts/plugins/jquery.cookie.js"></script>

    <script type="text/javascript">
        var index = parent.layer.getFrameIndex(window.name);
        $(function () {
            $("#cancel").click(function () {
                //parent.$("#handle_status").val('1112');
                //alert(parent.$("#handle_status").val());
                //parent.location.reload();
                parent.layer.close(index);
            });

           // $(".chosen-select").chosen();

            $("#submit").bind("click", Save); 
        })

        function Save() {
            var activation = $("#activation").val();

            var name = $.trim($("input[name=name]").val());
            if (name.length == 0) {
                layer.tips('名称不能为空！', 'input[name=name]', { tips: [2, '#78BA32'] });
                return false;
            }
            if (activation == "") {
                var user_id = $.trim($("#user_id").val());
                if (user_id.length == 0) {
                    layer.tips('所属账号不能为空！', '#user_id_chosen', { tips: [2, '#78BA32'] });
                    return false;
                }
            }

            var account = $.trim($("input[name=account]").val());
            if (account.length == 0) {
                layer.tips('账号不能为空！', 'input[name=account]', { tips: [2, '#78BA32'] });
                return false;
            }
            var password = $.trim($("input[name=password]").val());
            if (password.length == 0) {
                layer.tips('密码不能为空！', 'input[name=password]', { tips: [2, '#78BA32'] });
                return false;
            }
             
            var user_id = $("#user_id").val();
            var state = $("#state").val();
            var name = $("#name").val();
            var account = $("#account").val();
            var password = $("#password").val();
            
            common.invokeApi(
                "post",
                "/editRobot.html",
                { activation: activation, user_id: user_id, state: state, account: account, name: name, password: password, state: state },
                function () { },
                function (data) {
                    common.msg(data.Message, 1, function () {
                        window.location.href = "/robots.html";
                        //parent.location.reload();
                        //parent.layer.close(index);
                    });
                },
                function (data) {
                    common.msg(data.Message, 2, function () { });
                },
                function () { }
                );
        }

    </script>

}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" id="form1">
                        <input type="hidden" id="activation" name="activation" value="@(Model.activation)" /> 
                        <div class="form-group">
                            <label class="col-sm-2 control-label">名称<span style="color:red;">(*)</span>:</label>
                            <div class="col-sm-3">
                                <input type="text" id="name" name="name" maxlength="30" value="@(Model.name)" class="form-control" placeholder="输入名称">
                            </div>
                            <label class="col-sm-2 control-label">状态<span style="color:red;">(*)</span>：</label>
                            <div class="col-sm-3">
                                <select class="form-control" name="state" id="state">
                                    <option value="1" @(Model.state == 1 ? "selected" : "")>启用</option>
                                    <option value="0" @(Model.state == 0 ? "selected" : "")>禁用</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">账号<span style="color:red;">(*)</span>:</label>
                            <div class="col-sm-3">
                                <input type="text"  readonly id="account" name="account" maxlength="30" value="@(Model.account)" class="form-control" placeholder="输入账号">
                            </div>
                            <label class="col-sm-2 control-label">密码<span style="color:red;">(*)</span>:</label>
                            <div class="col-sm-3">
                                <input type="text" id="password" name="password" maxlength="30" value="@(Model.password)" class="form-control" placeholder="输入密码">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group" style="text-align:center;">
                            <button class="btn btn-primary" id="submit" type="button">提交</button>
                            
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>